package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyRuleGetDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyFeeRuleDTO;
import com.itlong.cloud.POJO.VO.property.PropertyRuleDetailVO;
import com.itlong.cloud.POJO.VO.property.PropertyRuleVO;
import com.itlong.cloud.project.property.IPropertyRuleServiceClient;
import com.itlong.cloud.property.service.IPropertyRuleService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <desc>
 *    物业收费规则 服务暴露接口实现类.
 * </desc>
 *
 * @createDate 2018-08-09
 */
@RestController
public class PropertyRuleServiceResource implements IPropertyRuleServiceClient {

    @Autowired
    IPropertyRuleService iPropertyRuleService;

    /**
     * <desc>
     *      分页获取 收费规则
     * <desc/>
     *
     * @param propertyRuleGetDTO 分页获取 物业信息条件对象
     * @return
     * @author Qiang.S
     * @createDate 2018-08-09
     */
    @Override
    @RequestMapping(path = "/expenses/rule/getRuleByPage",method = {RequestMethod.POST})
    public Page<PropertyRuleVO> getRuleByPage(@RequestBody PropertyRuleGetDTO propertyRuleGetDTO) throws Exception{
        Page<PropertyRuleVO> page = iPropertyRuleService.getRuleByPage(propertyRuleGetDTO);
        return  page;
    }

    /**
     * <desc>
     *      根据收费类型查询收费规则
     * <desc/>
     *
     * @param projectId 项目编号
     * @param feeType 收费类型：1抄表费 2物业费 3维修费 4停车费
     * @param feeCycle 收费周期：1月 2季度 3年
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/15
     */
    @Override
    @RequestMapping(path = "/expenses/rule/getRuleByFeeType",method = {RequestMethod.POST})
    public List<PropertyRuleVO> getRuleByFeeType(@RequestParam("projectId") String projectId,
                                                 @RequestParam("feeType") String feeType,
                                                 @RequestParam("feeCycle") String feeCycle) throws Exception{
        return  iPropertyRuleService.getRuleByFeeType(projectId,feeType,feeCycle);
    }

    /**
     * <desc>
     *     查询收费规则详情
     * <desc/>
     *
     * @param  feeRuleId  分页查询收费规则记录
     *  @param  projectId  项目编号
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/09
     */
    @Override
    @RequestMapping(path = "/expenses/rule/getRuleDetail",method = {RequestMethod.POST})
    public PropertyRuleDetailVO getRuleDetail(@RequestParam("feeRuleId") String feeRuleId, @RequestParam("projectId") String projectId) throws Exception{
        PropertyRuleDetailVO page = iPropertyRuleService.getRuleDetail(feeRuleId,projectId);
        return  page;
    }

    /**
     * <desc>
     *     新增收费规则
     * <desc/>
     *
     * @param  propertyFeeRuleDTO  收费规则信息
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/09
     */
    @Override
    @RequestMapping(path = "/expenses/rule/saveRule",method = {RequestMethod.POST})
    public Integer saveRule(@RequestBody PropertyFeeRuleDTO propertyFeeRuleDTO) throws Exception{
        return  iPropertyRuleService.saveRule(propertyFeeRuleDTO);
    }

    /**
     * <desc>
     *     判断规则名称是否重复
     * <desc/>
     *
     * @param  ruleName  收费规则名称
     * @param  projectId  项目编号
     * @param  feeRuleId  收费规则ID
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/10/24
     */
    @Override
    @RequestMapping(path = "/expenses/rule/checkRuleNameRepeat",method = {RequestMethod.POST})
    public Integer checkRuleNameRepeat(@RequestParam("ruleName") String ruleName, @RequestParam("projectId") String projectId, @RequestParam(value = "feeRuleId",required = false) String feeRuleId) throws Exception{
        return  iPropertyRuleService.checkRuleNameRepeat(ruleName,projectId,feeRuleId);
    }

    /**
     * <desc>
     *     更新收费规则
     * <desc/>
     *
     * @param  propertyFeeRuleDTO  收费规则信息
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/09
     */
    @Override
    @RequestMapping(path = "/expenses/rule/updateRule",method = {RequestMethod.POST})
    public Integer updateRule(@RequestBody PropertyFeeRuleDTO propertyFeeRuleDTO) throws Exception{
        return  iPropertyRuleService.updateRule(propertyFeeRuleDTO);
    }

    /**
     * <desc>
     *     删除收费规则
     * <desc/>
     *
     * @param  feeRuleId 收费规则ID
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/09
     */
    @Override
    @RequestMapping(path = "/expenses/rule/deleteRule",method = {RequestMethod.POST})
    public Integer deleteRule(@RequestParam("feeRuleId") String feeRuleId) throws Exception{
        return  iPropertyRuleService.deleteRule(feeRuleId);
    }

    /**
     * <desc>
     *     查询收费规则是否被绑定
     * <desc/>
     *
     * @param  feeRuleId 收费规则ID
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/09/03
     */
    @Override
    @RequestMapping(path = "/expenses/rule/deleteRuleCheck",method = {RequestMethod.POST})
    public Integer deleteRuleCheck(@RequestParam("feeRuleId") String feeRuleId) throws Exception{
        return  iPropertyRuleService.deleteRuleCheck(feeRuleId);
    }

    /**
     * <desc>
     *     根据账单编号获取最小收费日
     * <desc/>
     *
     * @param  feeId 账单编号
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/10/25
     */
    @Override
    @RequestMapping(path = "/expenses/rule/getMinFeeDay",method = {RequestMethod.POST})
    public String getMinFeeDay(@RequestParam("feeId") String feeId) throws Exception{
        return  iPropertyRuleService.getMinFeeDay(feeId);
    }

}
